<?php 
class UserController extends Zendvn_Controller_Action { 
	
	protected $_param;
	public function init(){
		parent::init();
		$template_path = TEMPLATE_PATH . "/public/white";
		$this->loadTemplate($template_path,'template.ini','template');
		$this->_param=$this->_request->getParams();
	}
	public function  indexAction(){
		$muser = new Default_Model_User();
		echo $muser->listall();
		echo "trung";
	}
	public function viewAction(){
		echo "view";
	}
	public function loginAction() {
		$submit= $this->_request->getParam('submit');
		$login = new Zendvn_System_Auth();
		if (isset($submit)&&!empty($submit)) {
			$flag=$login->login($this->_param);
			if($flag){
				$this->_redirect('/index/index');
			}else{
				echo $login->getError();
			}
		}
	}
	public function logoutAction(){
		$Auth = new Zendvn_System_Auth();
		$Auth->logout($this->_param);
	}
	
	public function errorAction(){
	
	}
	
	public function preDispatch() {
		$auth = Zend_Auth::getInstance();
		if (!$auth->hasIdentity()) {
			if ($this->_request->getActionName() != 'login') {
				$this->_redirect('/user/login');
			}
		}
	
	}
}

